#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @time     : 2018/3/23 17:26
# @Author   : BYF
# file      : preordain_page.py
# @version  :

from base_page import BasePage
from common import function
from time import sleep
from selenium.webdriver.common.by import By


class PreordainPage(BasePage):
    # Action
    iframe_loc = (By.CSS_SELECTOR, "iframe#iframe1")

    tenant_phone_loc = (By.CSS_SELECTOR, "input[name='tenant_phone']")  # 租客电话
    tenant_name_loc = (By.CSS_SELECTOR, "input[name='tenant_name']")  # 租客姓名
    tenant_idcard_loc = (By.CSS_SELECTOR, "input[name='tenant_idcard']")  # 证件号码

    rent_free_begin_time_loc = (By.CSS_SELECTOR, "input[name='rent_free_begin_time']")  # 免租开始日期
    rent_free_end_time_loc = (By.CSS_SELECTOR, "input[name='rent_free_end_time']")  # 免租结束日期
    end_time_loc = (By.CSS_SELECTOR, "input[name='end_time']")  # 预定结束日期
    sign_month_loc = (By.CSS_SELECTOR, "select[name='sign_month']")  # 计划签约月数
    Intentional_btn_loc = (By.CSS_SELECTOR, "input#optionsRadios1")  # 意向金按钮
    deposit_btn_loc = (By.CSS_SELECTOR, "input#optionsRadios2")  # 定金按钮

    ueto_employee_btn_loc = (By.CSS_SELECTOR, "select#example-multiple-selected+div.btn-group>button")  # 选择上户按钮
    ueto_employee_list_loc = (By.CSS_SELECTOR, "select#example-multiple-selected+div.btn-group>ul>li label")  # 上户列表
    with_employee_btn_loc = (By.CSS_SELECTOR, "select#go-with+div.btn-group>button")  # 选择上户按钮
    with_employee_list_loc = (By.CSS_SELECTOR, "select#go-with+div.btn-group>ul>li label")  # 上户列表
    sales_sources_loc = (By.CSS_SELECTOR, "select[name='sales_sources_id']")  # 销售来源

    book_money_loc = (By.CSS_SELECTOR, "input#book_money")  # 金额
    bill_number_loc = (By.CSS_SELECTOR, "input#bill_number")  # 票据号
    store_billing_time_loc = (By.CSS_SELECTOR, "input[name='store_billing_time']")  # 记账日期
    # diff_money_loc = ()
    pay_type_loc = (By.CSS_SELECTOR, "ul#pay_type a")  # 收支方式
    pay_money_loc = (By.CSS_SELECTOR, "div input:first-child")
    pay_explain_loc = (By.CSS_SELECTOR, "div input:last-child")

    remark_loc = (By.CSS_SELECTOR, "textarea[name'remark']")  # 备注

    save_btn_loc = (By.CSS_SELECTOR, "button#btn-ckin")  # 保存按钮
    cancel_btn_loc = (By.CSS_SELECTOR, "button#cancel-add")  # 取消按钮

    def _open(self, room_number):
        base_url = self.config.get("url", "base_url")
        preordain_url = self.config.get("url", "preordain_url") + str(room_number)
        self.open(base_url)
        function.add_cookies(self.driver)
        self.open(base_url + preordain_url)
        self.switch_to_iframe(self.iframe_loc)

    def complete_tenant_info(self,phone,name,idcard):
        self.send_keys(self.tenant_phone_loc,phone)
        sleep(5)
        self.send_keys(self.tenant_idcard_loc,name)
        self.send_keys(self.tenant_idcard_loc,idcard)

    def complete_preordain_info(self):
        pass

    def complete_sale_info(self):
        pass

    def complete_bill_info(self):
        pass

    # 完善备注信息
    def complete_remark(self, remark):
        self.send_keys(self.remark_loc, remark)  # 输入备注信息

    def click_save_btn(self):
        self.driver.find_element(*self.save_btn_loc).click()

    def preordain(self):#预定流程
        phone = 18080885489,
        name = u"小呜呜",
        idcard = "21040419870415452X"
        self._open(11949)
        self.complete_tenant_info(
            phone=phone,
            name=name,
            idcard=idcard
        )
